#ifndef RESPONSE_H 
#define RESPONSE_H

#include <sys/stat.h> 
#include <stdlib.h>
#include <time.h>
#include <sys/mman.h>
#include <fcntl.h> 
#include <unistd.h>
#include <ctype.h>  
#include <netinet/in.h> 
#include <sys/socket.h>
#include "parse.h"
#include "buffer.h"



typedef struct{
    const char *ext;
    const char *mime;
} Type_item;


extern Type_item mime_map[];


//请求方法的类型
typedef enum {
    METHOD_UNIMPLEMENT = -1,
    METHOD_GET,
    METHOD_HEAD,
    METHOD_POST
} METHOD_CLASS;


//错误响应信息
extern const char* RESPONSE_400;
extern const char* RESPONSE_404;
extern const char* RESPONSE_501;
extern const char* RESPONSE_505;

extern char* path_default;
extern char* status_line_200;
extern char* server_version;
extern char* null_line;

void get_content_type(char* content_type,char* path);
void get_date(char* date);
void get_content_length(char* content_length,struct stat* file_status);
char* get_connection(Request* request);
void get_last_modified(char* last_modified,struct stat* file_status);
void get_file_content(Buffer* bf,char* path);
char *getHeaderValue(Request *request, char *header_name);


//判断请求方法类型
METHOD_CLASS checkMethod(Request* request);
//解析请求
bool parseRequest(Buffer* bf_recv,struct sockaddr_in* cli_addr,int cli_sock);
//三个方法的具体处理
void getMethod(Request* request,struct sockaddr_in* client_addr,int cli_sock); 
void headMethod(Request* request,struct sockaddr_in* client_addr,int cli_sock);
void postMethod(Request* request,Buffer* bf_recv,struct sockaddr_in* cli_addr,int cli_sock);



#endif 